package com.burgeon.backend.SHOPBACKEND.rest;

import com.burgeon.backend.Rest.base.RESTBase;
import com.burgeon.backend.SHOPBACKEND.entity.ErpUserAndEmp;
import com.burgeon.backend.SHOPBACKEND.entity.YcVRetail;
import org.json.JSONArray;
import org.springframework.util.MultiValueMap;

import java.util.ArrayList;
import java.util.HashMap;

/*云仓派单未提交*/
public class QuerryYcRetailByDoNo extends RESTBase {

    private String ip;
    private String account;
    private String password;

    public QuerryYcRetailByDoNo(String ip, String account, String password) {
        this.ip = ip;
        this.account = account;
        this.password = password;
    }


    /**
     * 发送并接收字符创
     * @return
     */

    public ErpUserAndEmp getData(String doNo) throws Exception {
        String url = "http://" + ip + "/servlets/binserv/Rest";
        String str = RESULT(Data(doNo), url);
        System.err.println(str);
        String code = new JSONArray(str).getJSONObject(0).getString("code");
        if (!"0".equals(code)) {
            throw new Exception(str);
        }
        //System.err.println(str);
        String count = new JSONArray(str).getJSONObject(0).getString("count");
        JSONArray jsonArray = new JSONArray(str).getJSONObject(0).getJSONArray("rows");

       // ArrayList<YcVRetail> ycVRetails = new ArrayList<>();


        ErpUserAndEmp erpUserAndEmp = new ErpUserAndEmp();
        erpUserAndEmp.setUserEmpPhone(jsonArray.getJSONArray(0).getString(0));
        erpUserAndEmp.setUserEmpName(jsonArray.getJSONArray(0).getString(1));
        erpUserAndEmp.setUserName(jsonArray.getJSONArray(0).getString(2));
        erpUserAndEmp.setUserPhone(jsonArray.getJSONArray(0).getString(3));
        erpUserAndEmp.setCreatTime(jsonArray.getJSONArray(0).getString(4));

        return erpUserAndEmp;
    }

    private MultiValueMap Data(String doNo) {
        HashMap params = new HashMap();
        ArrayList columns = new ArrayList();//查询字段
        //columns.add("ID");
        columns.add("'C_VIP_ID;HR_EMPLOYEE_ID1;PHONE'");
        columns.add("'C_VIP_ID;HR_EMPLOYEE_ID1;NAME'");
        columns.add("'C_VIP_ID;VIPNAME'");
        columns.add("'C_VIP_ID;MOBIL'");
        columns.add("CREATIONDATE");

        params.put("columns", columns);
        params.put("table", "YC_RETAIL");//表名

        params.put("count","true");

        HashMap paramss = new HashMap();

        String status = "'"+doNo+"'";
        paramss.put("column", "DOCNO");
        paramss.put("condition", status);

        params.put("params", paramss);
        //System.err.println(params);

        return DATA("Query", params,account,password);
    }

    public static void main(String[] args) {
        QuerryYcRetailByDoNo querryYCRetailout = new QuerryYcRetailByDoNo("59.110.28.94:90", "nea@burgeon.com.cn", "burgeon55321");
        try {
            System.err.println(querryYCRetailout.getData("YCRE20092500005"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
